﻿using System;
using System.Runtime.Serialization;

namespace Bookvar.ObjectModel.Actions.Collaboration
{
    [Serializable]
    [DataContract]
    public class SayAction : ActionBase
    {
        private ICollaborationEventsPublisher collaborationEventsPublisher;
        private string message;
        private CollaborationUser sender;

        public SayAction()
        {
        }

        public SayAction( CollaborationUser sender, string message )
        {
            this.sender = sender;
            this.message = message;
        }

        public ICollaborationEventsPublisher CollaborationEventsPublisher
        {
            set { collaborationEventsPublisher = value; }
            get { return collaborationEventsPublisher; }
        }

        [DataMember]
        public CollaborationUser Sender
        {
            get { return sender; }
            set { sender = value; }
        }

        [DataMember]
        public string Message
        {
            get { return message; }
            set { message = value; }
        }

        public override void Execute( IExecutionContext context )
        {
            collaborationEventsPublisher.PublishUserSaid( Sender, Message );
            //ICollaborationEventsPublisher publisher = BookvarApplication.Current.ServiceLayer.GetService<ICollaborationEventsPublisher>();
            //publisher.PublishUserSaid(Sender, Message);
        }
    }
}